// @before-stub-for-debug-begin
#include <vector>
#include <string>
#include "commoncppproblem58.h"

using namespace std;
// @before-stub-for-debug-end

/*
 * @FilePath: \undefinedc:\Users\sxjct\.leetcode\58.最后一个单词的长度.cpp
 * @Brief: 
 * @Version: 1.0
 * @Date: 2021-03-16 18:41:44
 * @Author: your name
 * @Copyright: your copyright description
 * @LastEditors: your name
 * @LastEditTime: 2021-03-16 18:46:14
 */
/*
 * @lc app=leetcode.cn id=58 lang=cpp
 *
 * [58] 最后一个单词的长度
 */

// @lc code=start
class Solution {
public:
    int lengthOfLastWord(string s) {
        int length = 0;
        for(int i = s.size() - 1; i >= 0 ;i--)
        {
            if(s[i] != ' ')
                length++;
            else if(length != 0)
            {
                return length;
            }
        }
        return length;
    }
};
// @lc code=end

